import {
  userInfo, getSession, setSession
} from '../../utils/config'
import obj from '../../utils/auth'
const user = {
  state: {
    user: {
      name: '',
      avatar: '',
      gender: 0
    }
  },
  mutations: {
    SET_USER: (state, user) => {
      let u = getSession(userInfo)
      if (user.token) {
        obj.setToken(user.token)
      }
      state.user = Object.assign({}, u, user)
      setSession(userInfo, state.user)
    },
    REMOVE_USER: (state) => {
      state.user = {
        name: '',
        avatar: '//img.mukewang.com//54584d1d00015c0b02200220.jpg',
        gender: 0
      }
      setSession(userInfo, state.user)
    }
  }
}

export default user
